Skip to content

ESP-IDF + BLE OTA#89

Draft
zjwhitehead wants to merge 16 commits intomasterfrom
esp-idf
Draft

ESP-IDF + BLE OTA#89
zjwhitehead wants to merge 16 commits intomasterfrom
esp-idf

Conversation

@zjwhitehead
Copy link
Member

@zjwhitehead zjwhitehead commented Jan 26, 2026

Migrates the project to an ESP‑IDF + Arduino hybrid build, adds BLE OTA firmware updates compatible with Espressif’s Android app, and tightens OTA robustness/rollback behavior.
It also cleans up settings persistence and lint compliance.

Highlights

  • ESP‑IDF + Arduino hybrid build
    Updated the build setup and CMake layout to compile under ESP‑IDF while keeping Arduino libraries and setup()/loop() behavior.
  • BLE OTA (Espressif Android app compatible)
    Implemented the sector/CRC BLE OTA protocol, aligned service/characteristic UUIDs, and wired the OTA command/ACK + sector ACK flow to match Espressif’s client.
  • OTA reliability improvements
    Added rollback marking on successful boot, image length validation, CRC validation, sector resync handling, and proper abort handling.
  • Device settings refactor
    Settings persistence moved into a dedicated module, keeping preferences validation and serialization consistent.

Notes for reviewers

  • OTA is blocked when the device is ARMED/CRUISING.
  • BLE telemetry notifications are paused during OTA to avoid throughput conflicts.
  • Partition table + SDK defaults are included to enable OTA slots and rollback.

Introduces OTA (Over-the-Air) firmware update BLE service with new UUIDs and implementation files. Adds device settings management (header and source), updates build system for ESP-IDF/Arduino hybrid, and includes new partition and configuration files for dual OTA support. Also updates BMS CAN initialization and various build flags for improved compatibility.
Refactored OTA BLE service to use Espressif standard UUIDs and characteristics, separating command, data, and status. Added checks to suppress BLE notifications during OTA updates across all telemetry and config services. Improves compatibility and prevents notification conflicts during firmware updates.
Added CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE to sdkconfig.defaults to support OTA rollback. In main.cpp, added logic to mark the firmware as valid and cancel rollback after successful boot, ensuring OTA updates are confirmed.
Reworks OTA BLE service to use Espressif's sector-based protocol with CRC16 validation, sector buffering, and explicit ACK/ERR responses. OTA UUIDs are now NimBLEUUID constants for compatibility with official Espressif OTA apps. Improves reliability and error handling, and merges command/status characteristics as per Espressif's protocol.
Added tracking of total image length and received bytes during OTA updates. The service now validates that the received image size matches the expected size before completing the update, improving reliability and error handling. Also refined CRC and sector error handling to allow client-side retries instead of aborting the OTA process immediately.
Revised BLE OTA characteristic UUIDs to match Android esp-ble-ota-android app requirements and updated protocol handling in ota_service.cpp. ACK and command response logic now use new characteristics and payload formats. Also added 'rbl' as an alias for the 'reboot' serial command.
@zjwhitehead
Copy link
Member Author

Needs tested with this https://github.com/EspressifApps/esp-ble-ota-android

@zjwhitehead zjwhitehead added this to the v7.5 milestone Jan 27, 2026
@zjwhitehead
Copy link
Member Author

Likely conflicts with the work for #69

Replaces the previous CRC16 implementation with CRC16-CCITT (poly 0x1021, init 0) in ota_service.cpp to match the Espressif Android app. Updates all relevant CRC checks and calculations to use the new function.
Switched OTA BLE characteristics to use notify instead of indicate for ACKs and command responses, and added NOTIFY property to relevant characteristics. Added packet count logging and sector write progress in OTA service. In LVGL flush callback, ensured flush completion is signaled on SPI timeout to prevent deadlock, and moved CS pin selection after SPI bus acquisition. Added boot and running partition info logging during setup.
The setupAltimeter function no longer requires the alt_wire parameter, so it has been removed from the function signature and all call sites. This simplifies the interface and eliminates unused code.
BLE advertising is now started after the splash screen completes, rather than during BLE setup. This change ensures the device does not advertise until the UI is ready, improving startup flow and user experience. Added log messages to clarify advertising state.
Reorganize the main setup() into explicit boot phases, separating RTOS primitive creation, hardware initialization, UI setup, and task creation. Remove startup synchronization semaphores and flags in favor of a deterministic, phased boot. Move all queue and mutex creation to dedicated functions called before any tasks are started. Simplify UI task startup and ensure all dependencies are initialized before tasks run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant